/**
	* @author		Yuri Visser 		
	* @Created 		
	* @LastUpdated	
	* @Comments		
	* @Notes 			
	* 
**/

package com.theredspace.as3frameworks.puremvc.view {
	
	import com.theredspace.as3frameworks.puremvc.ApplicationFacade;
	import com.theredspace.as3frameworks.puremvc.view.components.Zoop;
	
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	import org.puremvc.as3.interfaces.IMediator;
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.patterns.mediator.Mediator;
	
	public class ZoopMediator extends Mediator implements IMediator {
		
		public var NAME:String;
		
		public function ZoopMediator(viewComponent:Object, id:String) {
			NAME = "zoopMediator_" + id;
			super(NAME, viewComponent);
			
			//---retrieve frequently consulted proxies
		}

		override public function onRegister():void {
			//Register all event listeners in here
			zoop.addEventListener(Zoop.KILL_ME_NOW, onKillMeNow);
			zoop.addEventListener(MouseEvent.CLICK, onZoopClicked);
		}
		
		override public function onRemove():void {
			//null vars and remove event listeners
			zoop.removeEventListener(Zoop.KILL_ME_NOW, onKillMeNow);
			zoop.removeEventListener(MouseEvent.CLICK, onZoopClicked);
		}
		
		override public function listNotificationInterests():Array {
			return	[
				ApplicationFacade.KILL_ZOOPS
			];
		}
				
		override public function handleNotification(note:INotification):void {
			 
			switch(note.getName()) {
				case ApplicationFacade.KILL_ZOOPS:
					zoop.killZoop();
					break;
				default:break;
			}
		}
		
        protected function get zoop():Zoop {
            return viewComponent as Zoop;
        }		
		
		protected function onKillMeNow(event:Event):void {
			facade.removeMediator(NAME);
		}
		
		protected function onZoopClicked(event:MouseEvent):void {
			zoop.scaleDownZoop();
			sendNotification(ApplicationFacade.ADD_CLONE_ZOOP, {
				creatureIconClass:zoop.creatureIconClass,
				creatureType:zoop.creatureType,
				x:zoop.x, y:zoop.y,
				width:zoop.width, height:zoop.height
			});
		}
		
		//-----------------------------------------------------------------
		//---cached proxies
		

	/************************************************************************/   
	}  //END CLASS
 
/****************************************************************************/  
}  //END PACKAGE